#ifndef HLS_M3U8_MESSAGE_H_
#define HLS_M3U8_MESSAGE_H_

#include <string>
#include <vector>

class HlsM3U8Message
{
public:
    struct Uri
    {
        std::string m_extinf; // tag : #EXTINF
        std::string m_index_uri;
    };
    struct StreamInfo   // tag #EXT-X-STREAM-INF
    {
        // #EXT-X-STREAM-INF:PROGRAM-ID=1, BANDWIDTH=460800, RESOLUTION=480x270
        // #EXT-X-STREAM-INF:PROGRAM-ID=1, BANDWIDTH=1228800, RESOLUTION=1280x720
        std::string m_program_id;
        std::string m_bindwidth;
        std::string m_resolution;
        std::string m_stream_url;
    };
public:
    HlsM3U8Message();
    void                      PlayListType(const std::string & type);
    void                      TargetDuration(const std::string & duration);
    void                      Version(const std::string & version);
    void                      MediaSequence(const std::string & sequence);
    void                      UriIndex(const std::string & extinf, const std::string & uri);
    std::string               PlayListType() const;
    double                    TargetDuration() const;
    int                       Version() const;
    int                       MediaSequence() const;
    std::vector<struct Uri> & UriIndex();
    void                      UpdateExtEndList(bool state);
    bool                      HasExtEndList() const;
    void                      Clear();
    void                      StreamInfoData(HlsM3U8Message::StreamInfo & stream_info);
    std::vector<StreamInfo> & StreamInfoData();
    int                       IncludeStreamInfo() const;
private:
    std::string m_flag;            // first line tag : #EXTM3U
    std::string m_playlist_type;   // playlist type tag : #EXT-X-PLAYLIST-TYPE
    std::string m_target_duration; // maximum media file duration tag : #EXT-X-TARGETDURATION
    std::string m_version;         // m3u version tag : #EXT-VERSION
    std::string m_media_sequence;  // m3u media file sequence tag : #EXT-X-MEDIA-SEQUENCE
    bool        m_has_ext_endlist; // m3u file end tag : #EXT-X-ENDLIST
private:
    std::vector<struct Uri> m_uri_vec;
    std::vector<StreamInfo> m_stream_info_vec;
};

class HlsM3U8MessageUtil
{
public:
    static int BuildM3U8Content(HlsM3U8Message * message, const std::string & abs_media_path, std::string & content);
    static std::string ComposePath(const std::string & base, const std::string & path);
};

#endif
